import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:laos_mall/common/style/app_style.dart';

class ItemWidget extends StatelessWidget {
  const ItemWidget(
      {super.key, this.prefixItem, this.suffixItem = "", this.titleStyle, this.subtitleStyle, this.space = 0, this.topSpace = 0, this.isExpand = false, this.mainAxisAlignment = MainAxisAlignment
          .start, this.crossAxisAlignment = CrossAxisAlignment
          .center, this.subTextAlign,this.isReverse = false,this.isColumn = false,this.isArrow = false});

  final dynamic prefixItem;
  final dynamic suffixItem;
  final TextStyle? titleStyle;
  final TextStyle? subtitleStyle;
  final double space;
  final bool isExpand;
  final MainAxisAlignment mainAxisAlignment;
  final CrossAxisAlignment crossAxisAlignment;
  final double topSpace;
  final TextAlign? subTextAlign;
  final bool isReverse;
  final bool isColumn;
  final bool isArrow;
  @override
  Widget build(BuildContext context) {

    if(isColumn){
    return isColumWidget();
    }
    return
      Padding(padding: EdgeInsets.only(top: topSpace), child:
      Row
        (
        mainAxisAlignment: mainAxisAlignment,
        crossAxisAlignment: isExpand
            ? CrossAxisAlignment.start
            : crossAxisAlignment,
        children: [
          if(prefixItem is String)
            Text(prefixItem, style: titleStyle ??
              (isReverse == true ? AppStyle.subtitleLightStyle : AppStyle.subtitleStyle ))
          else
            prefixItem
          ,
          SizedBox(width: space),
          if(suffixItem is String)
            buildSuffix()
          else
            if(isArrow)
              Row(children: [
                suffixItem,
                Icon(Icons.arrow_forward_ios,size: 13,),
              ],)
              else
                suffixItem
        ],));
  }

  isColumWidget(){
    return    Padding(padding: EdgeInsets.only(left: topSpace), child: Column( mainAxisAlignment: mainAxisAlignment,
      crossAxisAlignment: isExpand
          ? CrossAxisAlignment.start
          : crossAxisAlignment,
      children: [
        if(prefixItem is String)
          Text(prefixItem, style: titleStyle ??
              (isReverse == true ? AppStyle.subtitleStyle : AppStyle.subtitleLightStyle))
        else
          prefixItem
        ,
        SizedBox(width: space),
        if(suffixItem is String)
          buildSuffix()
        else
          suffixItem
      ]));
  }


  Widget buildSuffix() {
    Widget child = Text(suffixItem,
      style: subtitleStyle ??
          (isReverse == false ? AppStyle.subtitleLightStyle : AppStyle.subtitleStyle )
      ,
      textAlign:subTextAlign,);
    if (suffixItem is String) {
      if (isExpand == true) {
        child = Expanded(child: child);

      }
    } else {
      child = suffixItem;
    }
    if(isArrow)
      child =  Row(children: [
        child,
        SizedBox(width: 3,),
        Icon(Icons.arrow_forward_ios,size: 13,),
      ],);
    return child;
  }
}
